package week2;

import java.util.ArrayList;
import java.util.Scanner;

public class Main8 {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		ArrayList<String> strList=new ArrayList<String>();
		while (true){
			
		String a = sc.next();
		while(!a.equals("!!end!!")){
			strList.add(a);
			a=sc.next();
		}
		if(strList.size()>0){
			strList.add(0,"begin");
			strList.add(strList.size(),"end");
		}
		System.out.println(strList);
		String str = sc.next();
		int m=strList.indexOf(str);
		if(m<0){
			System.out.println("false");
			System.out.println(m);
		}
		else{
			System.out.println("true");
			System.out.println(m);
			
		}
		System.out.println(strList.lastIndexOf(str));
		//strList.lastIndexOf(str);
		System.out.print(strList.get(0)+"\n");
		strList.remove(0);
		System.out.println(strList);
		str = sc.next();
		strList.set(1,str);
		System.out.println(strList);
		str = sc.next();
		ArrayList<String> strList1=new ArrayList<String>();
		for(String p:strList){
			if(p.indexOf(str)>=0)
				strList1.add(p);
		}
		System.out.println(strList1);
		int x=strList.indexOf(str);
		if(x>=0){
			strList.remove(x);
		}
		System.out.println(strList);
		strList.clear();
		System.out.print(strList+" "+strList.size()+","+strList.isEmpty());
	}
	}
	
}
